package com.lww.feature.test.json;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Map;
import com.alibaba.fastjson.JSONReader;


/**
 * User: yian
 * Date: 2018/4/19
 */
public class Json2csv {

//    public static void main(String[] args) throws FileNotFoundException {
//        JSONReader reader = new JSONReader(new FileReader("/Users/lww/Desktop/wei123.json"));
//        reader.startArray();
//        final ArrayList<Integer> integers = new ArrayList<>();
//        integers.add(0);
//
//        while(reader.hasNext()) {
//            Map vo = reader.readObject(Map.class);
//            boolean pisdel = false;
//            Object deleted = vo.get("deleted");
//
//            if(null != deleted && ((Integer)deleted).equals(1)){
//                deleted=true;
//                System.out.println("deleted");
//            }
//
//
//
//
//            JSONArray driverList = (JSONArray)vo.get("driverList");
//            driverList.forEach(p->{
////                System.out.println(p);
//                Map map = JSONObject.toJavaObject((JSONObject) p, Map.class);
//
//                boolean isdel = false;
//                Object bindingState = map.get("bindingState");
//                if(null != bindingState && ((Integer)bindingState).equals(0)){
//                    isdel=true;
//                }
//
//
//
//                if (!isdel) {
//                    System.out.print(vo.get("phone"));
//                    System.out.print(",");
//                    System.out.print(map.get("userId"));
//                    System.out.print(",");
//                    System.out.print(map.get("flag"));
//                    System.out.println();
//                    Integer integer = integers.get(0);
//                    integers.set(0,integer+1);
//                }
//
//            });
////            System.out.println(vo);
//            // handle vo ...
//        }
//        System.out.println(integers.get(0));
//        reader.endArray();
//        reader.close();
//
//    }

    public static void main(String[] args) throws FileNotFoundException {
        JSONReader reader = new JSONReader(new FileReader("/Users/lww/Desktop/wei123.json"));
        reader.startArray();
        final ArrayList<Integer> integers = new ArrayList<>();
        integers.add(0);

        while(reader.hasNext()) {
            Map vo = reader.readObject(Map.class);
            boolean pisdel = false;
            Object deleted = vo.get("deleted");

            if(null != deleted && ((Integer)deleted).equals(1)){
                deleted=true;
                System.out.println("deleted");
            }
            System.out.print(vo.get("phone"));
            System.out.print(",");
            System.out.print(vo.get("created"));
            System.out.println();




//            System.out.println(vo);
            // handle vo ...
        }
        System.out.println(integers.get(0));
        reader.endArray();
        reader.close();

    }
}
